import request from '@/utils/request'

const PREFIX = '/system/dictdata'

/**
 * 分页查询字典数据
 */
export async function pageDictData(params) {
  const res = await request.get(`${PREFIX}/index`, { params })
  if (res.code === 0)
    return res.data

  return Promise.reject(new Error(res.msg))
}

/**
 * 查询字典数据列表
 */
export async function listDictData(params) {
  const res = await request.get(`${PREFIX}/index`, { params })
  if (res.code === 0 && res.data)
    return res.data

  return Promise.reject(new Error(res.msg))
}

/**
 * 新增/修改字典数据
 */
export async function updateDictData(data) {
  const res = await request.post(`${PREFIX}/edit`, data)
  if (res.code === 0)
    return res.msg

  return Promise.reject(new Error(res.msg))
}

/**
 * 删除字典数据
 */
export async function removeDictData(id) {
  const res = await request.post(`${PREFIX}/index`, { id })
  if (res.code === 0)
    return res.msg

  return Promise.reject(new Error(res.msg))
}
